<!-- 查看列表 -->
<template>
	<div>
		<el-dialog :visible.sync="show" width='80%' :before-close="closeDialog" :title="title">
			<!-- type 1  -->
			<el-table :data="list" class="tableScroll" style="width: 100%" border v-if="type == 1">
				<el-table-column align="center" prop="updateTime" label="修改时间"></el-table-column>
				<el-table-column align="center" prop="remarks" label="修改内容"></el-table-column>
			</el-table>
			<!-- end type 1  -->
			<!-- type 2  -->
			<el-table :data="list" style="width: 100%" border v-if="type == 2">
				<el-table-column align="center" prop="name" label="费用名称"></el-table-column>
				<el-table-column align="center" prop="price" label="金额"></el-table-column>
				<el-table-column align="center" prop="date" label="收费日期"></el-table-column>
			</el-table>
			<!-- end type 2  -->
			<!-- 3认购库存管理操作日志 -->
			<el-table :data="list" style="width: 100%" border v-if="type == 3">
				<el-table-column align="center" prop="name" label="类型"></el-table-column>
				<el-table-column align="center" prop="price" label="合同编号"></el-table-column>
				<el-table-column align="center" prop="date" label="出库记录编号"></el-table-column>
				<el-table-column align="center" prop="date" label="检码单号"></el-table-column>
				<el-table-column align="center" prop="date" label="操作人"></el-table-column>
				<el-table-column align="center" prop="date" label="外标"></el-table-column>
				<el-table-column align="center" prop="date" label="国标"></el-table-column>
				<el-table-column align="center" prop="date" label="总金额"></el-table-column>
				<el-table-column align="center" prop="date" label="操作时间"></el-table-column>
			</el-table>
			<!-- end 3认购库存管理操作日志 -->
			<!-- 4 仓库管理-出库记录-点提货指令编号 -->
			<el-table :data="list" style="width: 100%" border v-if="type == 4">
				<el-table-column align="center" prop="woodNumber" label="根号"></el-table-column>
				<el-table-column align="center" prop="length" label="长度(m)"></el-table-column>
				<el-table-column align="center" prop="diameter" label="直径(cm)"></el-table-column>
				<el-table-column align="center" prop="nationQuantity" label="国标"></el-table-column>
				<el-table-column align="center" prop="foreignQuantity" label="外标"></el-table-column>
			</el-table>
			<!-- end 4 仓库管理-出库记录-点提货指令编号 -->
			<!-- 5 报表管理-剩余库存统计-剩余外标库存 -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 5">
				<el-table-column align="center" prop="checkCode" label="检码单号"></el-table-column>
				<el-table-column align="center" prop="goodsType" label="类型"></el-table-column>
				<el-table-column align="center" prop="shipNameLadingBillCode" label="船名/提单号" :width="flexColumnWidth('shipNameLadingBillCode',list)"></el-table-column>
				<el-table-column align="center" prop="warehouseName" label="仓库名称" :width="flexColumnWidth('warehouseName',list)"></el-table-column>
				<el-table-column align="center" prop="heap" label="堆号"></el-table-column>
				<el-table-column align="center" prop="foreignQuantity" label="外标"></el-table-column>
				<el-table-column align="center" prop="inTotal" label="入库外标"></el-table-column>
				<el-table-column align="center" prop="status" label="状态"></el-table-column>
			</el-table>
			<!-- end 5 报表管理-剩余库存统计-剩余外标库存 -->
			<!-- type 6  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 6">
				<el-table-column align="center" prop="contractCode" label="采购合同号" width='120'></el-table-column>
				<el-table-column align="center" prop="contractSignedDate" label="合同签订日期"></el-table-column>
				<el-table-column align="center" prop="tradeType" label="贸易类型"></el-table-column>
				<el-table-column align="center" prop="companyName" label="卖方公司名称" :width="flexColumnWidth('companyName',list)"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
				<el-table-column align="center" prop="originalCountry" label="原产国" :width="flexColumnWidth('originalCountry',list)"></el-table-column>
				<el-table-column align="center" prop="paymentType" label="付款方式"></el-table-column>
				<el-table-column align="center" prop="priceClause" label="价格条款"></el-table-column>
			</el-table>
			<!-- end type6  -->
			<!-- type 7  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 7">
				<el-table-column align="center" prop="checkCode" label="检码单号" width='120'></el-table-column>
				<el-table-column align="center" prop="heap" label="堆号"></el-table-column>
				<el-table-column align="center" prop="goodsName" label="品名" :width="flexColumnWidth('goodsName',list)"></el-table-column>
				<el-table-column align="center" prop="inTotal" label="入库外标"></el-table-column>
				<el-table-column align="center" prop="inUnitCost" label="入库单位成本"></el-table-column>
				<el-table-column align="center" prop="warehouseName" label="仓库名称" :width="flexColumnWidth('warehouseName',list)"></el-table-column>
				<el-table-column align="center" prop="treeType" label="树种"></el-table-column>
				<el-table-column align="center" prop="quantity" label="根（件）数"></el-table-column>
				<el-table-column align="center" prop="nationQuantity" label="国标"></el-table-column>
				<el-table-column align="center" prop="cost" label="成本金额"></el-table-column>
			</el-table>
			<!-- end type7  -->
			<!-- type 8  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 8">
				<el-table-column align="center" prop="goodsName" label="品名"></el-table-column>
				<el-table-column align="center" prop="treeType	" label="树种"></el-table-column>
				<el-table-column align="center" prop="customerName" label="认购客户"></el-table-column>
				<el-table-column align="center" prop="nationQuantity" label="材积"></el-table-column>
				<el-table-column align="center" prop="unitPrice" label="单价"></el-table-column>
				<el-table-column align="center" prop="amount" label="含税金额"></el-table-column>
				<el-table-column align="center" prop="amountWithOutTax" label="不含税金额"></el-table-column>
				<el-table-column align="center" prop="foreignQuantity" label="外标"></el-table-column>
				<el-table-column align="center" prop="unitCost" label="单位成本"></el-table-column>
				<el-table-column align="center" prop="unitCost" label="成本"></el-table-column>
				<el-table-column align="center" prop="profit" label="盈亏"></el-table-column>
			</el-table>
			<!-- end type8  -->
			<!-- type 9  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 9">
				<el-table-column align="center" prop="checkCode" label="检码单号"></el-table-column>
				<el-table-column align="center" prop="heap" label="堆号"></el-table-column>
				<el-table-column align="center" prop="goodsName" label="品名" :width="flexColumnWidth('goodsName',list)"></el-table-column>
				<el-table-column align="center" prop="inTotal" label="入库外标"></el-table-column>
				<el-table-column align="center" prop="unitPrice" label="单价"></el-table-column>
				<el-table-column align="center" prop="warehouseName" label="仓库名称" :width="flexColumnWidth('warehouseName',list)"></el-table-column>
				<el-table-column align="center" prop="treeType" label="树种"></el-table-column>
				<el-table-column align="center" prop="quantity" label="根（件）数"></el-table-column>
				<el-table-column align="center" prop="nationQuantity" label="国标"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
			</el-table>
			<!-- end type9  -->
			<!-- type 10  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 10">
				<el-table-column align="center" prop="checkCode" label="检码单号"></el-table-column>
				<el-table-column align="center" prop="heap" label="堆号"></el-table-column>
				<el-table-column align="center" prop="goodsName" label="品名" :width="flexColumnWidth('goodsName',list)"></el-table-column>
				<el-table-column align="center" prop="inTotal" label="入库外标"></el-table-column>
				<el-table-column align="center" prop="inUnitCost" label="入库单位成本"></el-table-column>
				<el-table-column align="center" prop="warehouseName" label="仓库名称" :width="flexColumnWidth('warehouseName',list)"></el-table-column>
				<el-table-column align="center" prop="treeType" label="树种"></el-table-column>
				<!-- <el-table-column
          align="center"
          prop="quantity"
          label="根（件）数"
        ></el-table-column> -->
				<el-table-column align="center" prop="nationQuantity" label="国标"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
			</el-table>
			<!-- end type10  -->
			<!-- type 11  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 11">
				<el-table-column align="center" prop="checkCode" label="检码单号"></el-table-column>
				<el-table-column align="center" prop="heap" label="堆号"></el-table-column>
				<el-table-column align="center" prop="goodsName" label="品名" :width="flexColumnWidth('goodsName',list)"></el-table-column>
				<el-table-column align="center" prop="treeType" label="树种"></el-table-column>
				<el-table-column align="center" prop="warehouseName" label="仓库名称" :width="flexColumnWidth('warehouseName',list)"></el-table-column>
				<el-table-column align="center" prop="customerName" label="客户名称"></el-table-column>
				<el-table-column align="center" prop="ladingDate" label="提货日"></el-table-column>
				<el-table-column align="center" prop="notOutQuantity" label="未出库数量"></el-table-column>
			</el-table>
			<!-- end type11  -->
			<!-- type 12  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 12">
				<el-table-column align="center" prop="code" label="信用证编号"></el-table-column>
				<el-table-column align="center" prop="contractCode" label="合同编号"></el-table-column>
				<el-table-column align="center" prop="date" label="开证日期"></el-table-column>
				<el-table-column align="center" prop="bankName" label="开证银行"></el-table-column>
				<el-table-column align="center" prop="creditType" label="信用证类型"></el-table-column>
				<el-table-column align="center" prop="creditCode" label="信用证号码"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
			</el-table>
			<!-- end type12  -->
			<!-- type 13  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 13">
				<el-table-column align="center" prop="interest" label="货款利息"></el-table-column>
				<el-table-column align="center" prop="currency" label="货款利息币种"></el-table-column>
				<el-table-column align="center" prop="interestRate" label="货款利息汇率"></el-table-column>
				<el-table-column align="center" prop="bankActualInterest" label="货款利息人民币"></el-table-column>
				<el-table-column align="center" prop="paymentBankName" label="银行"></el-table-column>
			</el-table>
			<!-- end type13  -->
			<!-- type 14  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 14">
				<el-table-column align="center" prop="code" label="付款编号"></el-table-column>
				<el-table-column align="center" prop="contractCode" label="合同编号"></el-table-column>
				<el-table-column align="center" prop="paymentDate" label="开证日期"></el-table-column>
				<el-table-column align="center" prop="paymentBankName" label="开证银行"></el-table-column>
				<el-table-column align="center" prop="paymentType" label="付款方式"></el-table-column>

				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
				<el-table-column align="center" prop="financingForm" label="融资形式"></el-table-column>
			</el-table>
			<!-- end type14  -->
			<!-- type 15  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 15">
				<el-table-column align="center" prop="paymentDate" label="付款日期"></el-table-column>
				<el-table-column align="center" prop="paymentBankName" label="付款银行"></el-table-column>
				<el-table-column align="center" prop="paymentType" label="付款方式"></el-table-column>

				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
			</el-table>
			<!-- end type15  -->
			<!-- type 16  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 16">
				<el-table-column align="center" prop="code" label="编号" width="120"></el-table-column>
				<el-table-column align="center" prop="companyName" label="卖方公司名称" :width="flexColumnWidth('companyName',list)"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
			</el-table>
			<!-- end type16  -->
			<!-- type 17  -->
			<el-table show-summary :data="list" style="width: 100%" border v-if="type == 17">
				<el-table-column align="center" prop="paymentCode" label="付款编号"></el-table-column>
				<el-table-column align="center" prop="contractCode" label="合同号"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="quantity" label="数量 "></el-table-column>
				<el-table-column align="center" prop="currency" label="币种 "></el-table-column>
				<el-table-column align="center" prop="docCode" label="单证编号 "></el-table-column>
				<el-table-column align="center" prop="shipName" label="船名 " :width="flexColumnWidth('shipName',list)"></el-table-column>
				<el-table-column align="center" prop="ladingBillCode" label="提单号  "></el-table-column>
				<el-table-column align="center" prop="status" label="状态 "></el-table-column>
			</el-table>
			<!-- end type17  -->
			<!-- type 18  -->
			<el-table show-summary :data="list" style="width: 100%" :summary-method="getSummaries" border v-if="type == 18">
				<el-table-column align="center" prop="code" label="付款编号"></el-table-column>
				<el-table-column align="center" prop="companyName" :width="flexColumnWidth('companyName',list)" label="卖方名称"></el-table-column>
				<el-table-column align="center" prop="paymentBankName" label="付款银行"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额"></el-table-column>
				<el-table-column align="center" prop="remarks" label="备注" :width="flexColumnWidth('shipName',list)"></el-table-column>

			</el-table>
			<!-- end type18  -->
			<!-- type 19  -->
			<el-table show-summary :data="list" style="width: 100%" border :summary-method="getSummaries" v-if="type == 19">
				<el-table-column align="center" fixed="left" prop="code" label="单证编号" :width="flexColumnWidth('code',list)"></el-table-column>
				<el-table-column align="center" prop="receiveBillDate" :width="flexColumnWidth('receiveBillDate',list)" label="到单日期"></el-table-column>
				<el-table-column align="center" prop="contractCode" label="合同号" :width="flexColumnWidth('contractCode',list)"></el-table-column>
				<el-table-column align="center" prop="invoiceCode" label="发票号" :width="flexColumnWidth('invoiceCode',list)"></el-table-column>
				<el-table-column align="center" prop="shipName" label="船名" :width="flexColumnWidth('shipName',list)"></el-table-column>
				<el-table-column align="center" prop="ladingBillCode" label="提单号" :width="flexColumnWidth('ladingBillCode',list)"></el-table-column>
				<el-table-column align="center" prop="customsCode" label="报关单号" :width="flexColumnWidth('customsCode',list)"></el-table-column>
				<el-table-column align="center" prop="currency" label="币种" :width="flexColumnWidth('currency',list)"></el-table-column>
				<el-table-column align="center" prop="amount" label="金额" :width="flexColumnWidth('amount',list)"></el-table-column>
				<el-table-column align="center" prop="offsetAmount" label="冲抵金额"></el-table-column>
				<el-table-column align="center" prop="actualPaymentAmount" label="实际付款金额" :width="flexColumnWidth('actualPaymentAmount',list)"></el-table-column>
				<el-table-column align="center" prop="paymentType" label="付款方式" :width="flexColumnWidth('paymentType',list)"></el-table-column>
				<el-table-column align="center" fixed="right" prop="inventoryStatus" label="入库状态" :width="flexColumnWidth('inventoryStatus',list)"></el-table-column>
				<el-table-column align="center" label="操作" v-if="$store.state.operateShow" width="100px" fixed="right">
					<template slot-scope="scope">
						<el-popconfirm title="确定入库吗？" placement="top" @confirm="in_doc(scope.row)" v-if="scope.row.inventoryStatus == '未入库'">
							<el-button slot="reference" type="primary" size="small" style="margin-right: 10px">
								入库
							</el-button>
						</el-popconfirm>
					</template>
				</el-table-column>
			</el-table>
			<!-- end type19  -->
		</el-dialog>
	</div>
</template>
<script>
export default {
	name: 'lookTable',
	props: {
		show: {
			type: Boolean,
			default: false,
		},
		list: Array,
		title: {
			type: String,
			default: '查看信息',
		},
		type: {
			type: Number,
			default: 1,
			// type1 合同修改 信用证修改 type2信用证费用 type3认购库存管理操作日志 type4 仓库管理-出库记录-点提货指令编号
			// type5 报表管理-剩余库存统计-剩余外标库存
			// 报表管理-到货销售情况报表 （type6：船名/提单号 type7 数量 成本金额   type8 盈亏 type9 已认购 数量,金额
			// type10 未认购 数量金额 type11 已认购未出库数量）
			//type 12 采购统计-银行结算明细统计-开证统计 type 13 采购统计-购付汇率明细统计-货款统计
			//type 14 采购统计-银行结算明细统计-融资统计
			//type 15 采购统计-银行结算明细统计-结算统计
			//type 16 财务管理-采购管理查询-采购合同明细
			//type 17 财务管理-货物在途明细
			//type 18 财务管理-预付货款明细-付款金额
			//type 19 财务管理-预付货款明细-已到货金额
		},
	},
	data() {
		return {};
	},
	methods: {
		in_doc(row) {
			const params = { id: row.id };
			this.$myApi.in_doc(params).then((res) => {
				if (res.code == 200) {
					this.$message.success('操作成功');
					this.$emit('getData');
				}
			});
		},
		closeDialog() {
			console.log('close');
			this.$emit('closeShow');
		},
		getSummaries(param) {
			const { columns, data } = param;
			const sums = [];
			columns.forEach((column, index) => {
				if (index === 0) {
					sums[index] = '合计';
					return;
				}
				if (this.type == 19) {
					if (
						column.label != '金额' &&
						column.label != '冲抵金额' &&
						column.label != '实际付款金额'
					) {
						//合计部分
						return;
					}
				}
				if (this.type == 18) {
					if (column.label != '金额') {
						//合计部分
						return;
					}
				}
				const values = data.map((item) =>
					Number(item[column.property])
				);
				if (!values.every((value) => isNaN(value))) {
					sums[index] = values.reduce((prev, curr) => {
						const value = Number(curr);
						if (!isNaN(value)) {
							return prev + curr;
						} else {
							return prev;
						}
					}, 0);
					// sums[index] += ' 元';
					sums[index] = sums[index].toFixed(2);
				} else {
					// sums[index] = 'N/A';
				}
			});
			// console.log(sums);

			return sums;
		},
	},
};
</script>
